def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def word_to_number(word):
    return {
        'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
        'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
    }[word]

def find_nearest_prime(number):
    lower = number - 1
    upper = number + 1
    while True:
        if is_prime(lower):
            return lower
        if is_prime(upper):
            return upper
        lower -= 1
        upper += 1

def main():
    words = input().split()
    if len(words) != 3 or not all(word in ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] for word in words):
        print("Wrong input")
        return
    number = word_to_number(words[0]) * 100 + word_to_number(words[1]) * 10 + word_to_number(words[2])
    print(find_nearest_prime(number))

if name == "main":
    main()
